from pydantic import BaseModel, Field, UUID4
from typing import Optional
from enum import Enum

class IssueSeverity(str, Enum):
    HIGH = 'high'
    MEDIUM = 'medium'
    LOW = 'low'

class IssueType(str, Enum):
    TYPO = 'typo'
    SEMANTIC = 'semantic'
    RISK_LEVEL = 'risk-level'
    COMPLIANCE_STATUS = 'compliance-status'

class IssueBase(BaseModel):
    """Base schema for issue operations."""
    plan_id: UUID4 = Field(..., description="关联的评估计划ID")
    item_id: UUID4 = Field(..., description="关联的检查项ID")
    type: IssueType = Field(..., description="问题类型")
    severity: IssueSeverity = Field(..., description="严重程度")
    title: str = Field(..., max_length=255, description="原始标题")
    description: str = Field(..., description="问题描述")
    suggestion: str = Field(..., description="改进建议")
    original_content: Optional[str] = Field(None, description="原始内容")
    original_description: Optional[str] = Field(None, description="原始描述")

class IssueCreate(IssueBase):
    """Schema for creating a new issue."""
    id: UUID4 = Field(..., description="问题ID")

class IssueUpdate(BaseModel):
    """Schema for updating an existing issue."""
    type: Optional[IssueType] = None
    severity: Optional[IssueSeverity] = None
    title: Optional[str] = None
    description: Optional[str] = None
    suggestion: Optional[str] = None
    original_content: Optional[str] = None
    original_description: Optional[str] = None

class IssueInDBBase(IssueBase):
    """Base schema for issue in database."""
    id: UUID4 = Field(..., description="问题ID")

    class Config:
        from_attributes = True

class IssueDeleteRequest(BaseModel):
    """Schema for deleting multiple issues."""
    ids: list[UUID4] = Field(..., description="要删除的问题ID列表")


class Issue(IssueInDBBase):
    """Schema for returning an issue."""
    pass
